<template>
  <div class="admin-login">
      <div class="login-out-btn">
        <el-button icon="el-icon-switch-button" @click="loginOut">退出登录</el-button>
      </div>
      <div class="login-box">
          <h2 class="login-flag">
          </h2>
          <div class="active-tip color-danger">请激活您的账号,7天未激活账号将会被删除.<br>若账号被删除请联系管理员!</div>
          <div class="input-box">
              <div class="form-item">
                  <el-input placeholder="请输入旧密码" type="password" prefix-icon="el-icon-lock" v-model.trim="oldPassword" maxlength="15" clearable></el-input>
              </div>
              <div class="form-item">
                  <el-input placeholder="新密码" type="password" prefix-icon="el-icon-lock" v-model.trim="password" maxlength="15" clearable></el-input>
              </div>
              <div class="form-item">
                  <el-input placeholder="确认新密码" type="password" prefix-icon="el-icon-lock" v-model.trim="rePassword" maxlength="15" clearable></el-input>
              </div>
              <el-button type="primary" round @click="login" v-loading.fullscreen.lock="isLoading">激活账号,进入系统</el-button>
          </div>
      </div>
  </div>
</template>

<script>
import request from "@/utils/request";
import qs from "qs";
// import md5 from "js-md5";

export default {
  name: "ActivationLogin",
  data() {
    return {
      oldPassword: "",
      password: "",
      rePassword: ""
    };
  },
  methods: {
    login() {
      let that = this;
      let inputData = {
        oldPassword: "",
        password: "",
        rePassword: ""
      };
      //打开加载动画
      that.isLoading = true;
      // 使用封装的请求
      request({
        url: that.$api.login,
        headers: {
          "Content-Type": "application/x-www-form-urlencoded"
        },
        method: "POST",
        data: qs.stringify(inputData)
      })
        .then()
        .finally(() => {
          that.isLoading = false;
        });
    },
    loginOut() {
      this.$message({
        message: "退出登录",
        duration: "1000",
        type: "error",
        center: true
      });
      //清除cookie回到登录页面
      this.$store.dispatch("loginOut").then(res => {
        location.reload();
      });
    }
  }
};
</script>

<style lang="less" scoped>
.login-box {
  width: 521px;
  background: #fff;
  border-radius: 5px;
  box-shadow: 0px 10px 10px rgba(0, 0, 0, 0.05);
  position: absolute;
  left: 50%;
  top: 50%;
  margin-top: -238px;
  margin-left: -260px;
  overflow: hidden;
  .active-tip {
    font-size: 16px;
    line-height: 1.5;
    text-align: center;
    margin: 0 79px 20px;
  }
}
.admin-login {
  background: url(/static/images/login_bg.png);
  background-size: cover;
  height: 100%;
  width: 100%;
  position: fixed;
  left: 0;
  top: 0;
  .login-out-btn {
    position: absolute;
    right: 10px;
    top: 10px;
    color: #fff;
    cursor: pointer;
  }
  .login-flag {
    background: url(/static/images/login_text.png);
    margin-bottom: 10px;
    height: 178px;
    color: #fff;
    font-size: 2rem;
    line-height: 150px;
    text-align: center;
  }
  .input-box {
    padding-left: 120px;
    padding-right: 120px;
    padding-bottom: 50px;
  }
}
.el-button {
  display: block;
  width: 100%;
  box-shadow: 0px 3px 4px rgba(46, 161, 254, 0.1);
  padding: 15px;
  border-radius: 50px;
}
</style>
